﻿@{
    Layout = "~/Views/Shared/_Layout_RTU_block.cshtml";
    ViewBag.Title = "报警关注";
}

<div class="xds-no-breadcrumb">
    <div class="full-height">
        <div class="full-height-scroll white-bg border-left">
            <div id="warnloginterest" style="width:100%;height:100%">
                <table id="interesttable" style="width:100%"></table>
                <div class="col-lg-12" style="text-align:center;margin-top:50px;margin-bottom:50px">
                    <button class=" btn btn-w-m btn-primary" onclick="save()">保存</button>
                    <button class=" btn btn-w-m btn-primary" style="margin-left:20px" onclick="close()">返回</button>
                </div>
            </div>
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/iCheck/iCheckStyles")
    @Styles.Render("~/plugins/sweetAlertStyles")
    <style type="text/css">
        table tr td {
            padding: 5px 0px 0px 10px;
        }
    </style>
}
@section Scripts {
    @Scripts.Render("~/plugins/iCheck")
    @*@Scripts.Render("~/plugins/videoResponsible")*@
    @Scripts.Render("~/plugins/sweetAlert")
    <script type="text/javascript">
        $(document).ready(function () {
            fillinteresttable();
        });
        function fillinteresttable() {
            $("#interesttable").empty();
            $.ajax({
                url: "/Personal/WellWarnLog",
                method: 'GET',
                dataType: 'json',
                data: { wellid: sessionStorage.wellid },
                async: false,
                success: function (data) {
                    if (data.status == 2) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "You do not have permission!"
                        });
                    }
                    else if (data.status == 3) {
                        for (var i = 0; i < data.allwarnlog.length; i++) {
                            if (i % 4 == 0)
                                $("#interesttable").append('<tr id="interesttr' + parseInt(i / 4) + '" style="padding:3px 0 0 0;"></tr>')
                            $("#interesttr" + parseInt(i / 4)).append('<td><label class="checkbox-inline i-checks"> <input type="checkbox" name="interest" value="' + data.allwarnlog[i].IDCode.trim() + '" id="' + data.allwarnlog[i].IDCode.trim() + '">&nbsp;&nbsp;' + data.allwarnlog[i].Describe.trim() + '</label></td>')
                        }
                    }
                    else if (data.status == 0) {
                        var notignore = data.data;
                        for (var i = 0; i < data.allwarnlog.length; i++) {
                            if (i % 4 == 0)
                                $("#interesttable").append('<tr id="interesttr' + parseInt(i / 4) + '" style="padding:3px 0 0 0;"></tr>')
                            if (notignore.indexOf(data.allwarnlog[i].IDCode.trim()) >= 0)
                                $("#interesttr" + parseInt(i / 4)).append('<td><label class="checkbox-inline i-checks"> <input type="checkbox" name="interest" value="' + data.allwarnlog[i].IDCode.trim() + '" checked="" id="' + data.allwarnlog[i].IDCode.trim() + '">&nbsp;&nbsp;' + data.allwarnlog[i].Describe.trim() + '</label></td>')
                            else
                                $("#interesttr" + parseInt(i / 4)).append('<td><label class="checkbox-inline i-checks"> <input type="checkbox" name="interest" value="' + data.allwarnlog[i].IDCode.trim() + '" id="' + data.allwarnlog[i].IDCode.trim() + '">&nbsp;&nbsp;' + data.allwarnlog[i].Describe.trim() + '</label></td>')
                        }
                    }
                }
            });
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        }
        function close() {
            window.open("/Personal/ManageWarnLog", "_self")
        }
        function save() {
            var str = "";
            $("input[name='interest']:checkbox").each(function () {
                if (true == $(this).is(':checked')) {
                    str += $(this).val() + " ";
                }
            });
            $.ajax({
                url: "/Personal/UpdateWarnLog",
                method: 'GET',
                dataType: 'json',
                data: { wellid: sessionStorage.wellid, warnlogstr: str },
                async: false,
                success: function (data) {
                    if (data.status == 2) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "You do not have permission!"
                        });
                    }
                    else if (data.status == 3) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "Sorry, an unknown error occurred."
                        });
                    }
                    else if (data.status == 0) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "Successfully update the alarm list."
                        });
                        window.open("/Personal/ManageWarnLog", "_self")
                    }
                }
            });
        }
    </script>
}